import os
import random


class ReadFile:
    def __init__(self, directory, tail):
        self.full_path = []
        self.__directory = directory
        self.__tail = tail

    def __get_all_file_paths(self):
        for file_name in os.listdir(self.__directory):
            self.full_path.append(os.path.join(self.__directory, file_name))

    def __check_file_type(self):
        del_list = []
        for file in self.full_path:
            if not file.endswith(self.__tail):
                del_list.append(file)
        for file in del_list:
            self.full_path.remove(file)

    def run(self):
        # get file names
        self.__get_all_file_paths()
        # control the file type
        self.__check_file_type()
        # shuffle the names
        random.shuffle(self.full_path)
